% This function is to approximate the hypervolume of a given PF
% 
% Inputs : M - number of objectives
%          PF - Pareto objective vectors
%          nadir - the nadir point (used to normalize PF)
%          Ref - the scalar value of referenec point, e.g., 1, or 1.2
%       
% Outputs : approximatedHV - hypervolume value
%%
%{ 
Please cite the paper while using this code

Wang, R., Purshouse, R. C., Fleming, P. J., Preference-inspired co-evol-
utionary algorithms for many objective optimisation, IEEE Transactions on 
Evolutionary Computation., 17 (4), 474-494, 2013. 
@Article{wang2012piceag,
  Title                    = {{Preference-inspired Co-evolutionary Algorithms for Many-objective Optimisation}},
  Author                   = {Wang, Rui and Purshouse, Robin C. and Fleming, Peter J.},
  Journal                  = {IEEE Transactions on Evolutionary Computation},
  Year                     = {2013},
  Number                   = {4},
  Pages                    = {474--494},
  Volume                   = {17},
  Publisher                = {IEEE}
}
%}
%%
% Author: Rui Wang   ruiwangnudt@gmail.com
% Date : 13 Mar 2011

function approximatedHV=HypMontle(M,PF,nadir,Ref)
if nargin < 4,  Ref = 1; end
solNum =size(PF,1);
runs = M;
tempHV = zeros(1,runs);
Nind = M*5000;
PF = PF./rep(nadir,[solNum 1]);
for irun = 1:runs
    randomSet = Ref*rand(Nind,M);
    dominated_ratio = cMetric(PF, randomSet); % This function is to compute the proportion of the generated points that are dominated by the PF. This returns a ratio within [0 1]
    tempHV(irun) = Ref*dominated_ratio;
end
approximatedHV = mean(tempHV);


